package  
{
	import cn.antscrpt.antLib.Cil;
	import cn.antscrpt.antLib.logo.CustomTriangle3D;
	import cn.antscrpt.antLib.logo.Logo3D;
	import cn.antscrpt.antLib.logo.PointData;
	import flash.display.DisplayObject;
	import flash.display.TriangleCulling;
	import flash.events.Event;
	import gs.TweenLite;
	import gs.easing.*
	import org.papervision3d.core.geom.renderables.Triangle3D;
	import org.papervision3d.core.geom.renderables.Triangle3DInstance;
	import org.papervision3d.core.geom.renderables.Vertex3D;
	import org.papervision3d.core.geom.TriangleMesh3D;
	import org.papervision3d.core.geom.Vertices3D;
	import org.papervision3d.materials.ColorMaterial;
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.objects.primitives.Cylinder;
	import org.papervision3d.objects.primitives.Sphere;
	import org.papervision3d.view.BasicView;
	
	/**
	 * ...
	 * @author microthink AntScript
	 */
	public class Test extends BasicView
	{

			
		public function Test() 
		{
			
			
			var material:ColorMaterial = new ColorMaterial(0xcc0000);
			material.doubleSided = true;
 
			//all the 200's are points of a triangle
			var vertex3D_1:Vertex3D = new Vertex3D(-200, -200, 0);
			var vertex3D_2:Vertex3D = new Vertex3D(200, -200, 0);
			var vertex3D_3:Vertex3D = new Vertex3D(-200, 200, 0);
 
			var triangleVertices:Array = [vertex3D_1, vertex3D_2, vertex3D_3];
 
			//use null because we haven't created its parent mesh yet			
			var triangle3d:Triangle3D = new Triangle3D(null, triangleVertices, material);
			var triangleFaces:Array = [triangle3d];
 
			
			var triangleMesh3d:TriangleMesh3D = new TriangleMesh3D(material, triangleVertices, triangleFaces, null);
			//for the triangle to be "renderable", it needs to know who its daddy is
			//this is the same property as the "null" parameter a few lines above
			triangle3d.instance = triangleMesh3d;
			
		
			
			var s:DisplayObject3D = new DisplayObject3D("ddd");
			for (var i:int = 0; i < PointData.FRAME_POINT_3D.length; i++) 
			{
				
				s.addChild(new CustomTriangle3D(material, PointData.FRAME_POINT_3D[i]), "t" + i);
				s.getChildByName("t" + i).x = Math.random() *400-200;
				s.getChildByName("t" + i).y = Math.random() *400-200;
				s.getChildByName("t" + i).z = Math.random() *30-15;
				s.getChildByName("t" + i).rotationX = Math.random() * 180;
				s.getChildByName("t" + i).rotationY = Math.random() * 180;
				s.getChildByName("t" + i).rotationZ = Math.random() * 180;
			}
			for (i = 0; i < PointData.SHAPE_POINT_3D.length; i++) 
			{
				s.addChild(new CustomTriangle3D(material, PointData.SHAPE_POINT_3D[i]), "s" + i);
				s.getChildByName("s" + i).x = Math.random() *400-200;
				s.getChildByName("s" + i).y = Math.random() *400-200;
				s.getChildByName("s" + i).z = Math.random() *30-15;
				s.getChildByName("s" + i).rotationX = Math.random() * 180;
				s.getChildByName("s" + i).rotationY = Math.random() * 180;
				s.getChildByName("s" + i).rotationZ = Math.random() * 180;
			}
			scene.addChild(new Cylinder(new ColorMaterial(0xffffff), 200, 900, 5, 20, 200, true, true),  "ddd");
			startRendering();

			s.scale = 5;
			
			for (i = 0; i < PointData.FRAME_POINT_3D.length; i++) 
			{
				TweenLite.to(s.getChildByName("t" + i),Math.random()*2,{x:0,y:0,z:0,rotationX:0,rotationY:0,rotationZ:0,ease:Cubic.easeIn});
			}
			for (i = 0; i < PointData.SHAPE_POINT_3D.length; i++) 
			{
				TweenLite.to(s.getChildByName("s" + i),Math.random()*1+2,{x:0,y:0,z:0,rotationX:0,rotationY:0,rotationZ:0,ease:Cubic.easeIn});
			}
		}
		override protected function onRenderTick(event:Event=null):void
		{
			scene.getChildByName("ddd").rotationY = -viewport.containerSprite.mouseX / 2;
			scene.getChildByName("ddd").rotationX = -viewport.containerSprite.mouseY / 2;
			super.onRenderTick(event);
		}

	}
	
}